home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 1989.ZIP / QQUERY.ZIP / QQDMEDIT.PRG < prev    next >
Text File  |  1990-05-19  |  6KB  |  209 lines

  1. * QQDMEDIT.PRG  simple program to customize QDM files
  2.  
  3. * Use this program to modify existing QDM files.  You will be using a Fox
  4. * text editor to make changes:
  5. *   Modify the default field names pop up menu title
  6. *   Change the content of any field name line
  7. *   Add new lines
  8. *   Delete existing lines
  9. *   Add new children files and fields
  10. *   Blank lines will be ignored
  11. * Restrictions:
  12. *   The 1st 10 characters of each field line is reserved for the field name
  13. *   The 1st  2 characters of each child alias line is reserved for 2 periods (..)
  14. *   The next 8 characters of each child alias line is reserved for the alias name
  15. *   Any lines longer than 49 charcters will be truncated.
  16. *
  17. * NOTE:  This program uses the FoxPro MODIFY COMMAND editor to change
  18. * existing data.  This program expects a backup file to be created whenever
  19. * a file is changed by MODIFY COMMAND.  If FoxPro is not configured to make
  20. * a backup, this program will not record any changes to your QDM files.
  21. *
  22. * To check your current FOXPRO configuration:
  23. *
  24. *      1. Start this progran and enter a QDM file name.
  25. *      2. At the editing window, invoke the FoxPro main menu (F10 key).
  26. *      3. Select the Edit menu.
  27. *      4. Select the "Preferences" dialog.
  28. *      5. If the option "Make backup" is not selected:
  29. *            a. Select "Make backup"
  30. *            b. Select "Use these preferences as default for .TXT files"
  31. *            c. Save the dialog  <<  OK  >>
  32.  
  33. * set the environment
  34. SET CONFIRM ON
  35. SET DELETED ON
  36. SET EXACT OFF
  37. SET SAFE OFF
  38. SET STATUS ON
  39. SET TALK OFF
  40. CLEAR ALL
  41. changing=.t.
  42.  
  43. * display any QDM files
  44. CLEAR
  45. qqbanner=REPL(CHR(178),31)+' Q Q U E R Y (tm) '+REPL(CHR(178),31)
  46. @ 0,0 GET qqbanner
  47. CLEAR GETS
  48. ? 'QDM files in the current directory:'
  49. ?
  50. DIR *.qdm
  51. ?
  52. ?
  53. qqrow=ROW()
  54. * get the name of a QDM file to work with
  55. DO WHILE TYPE('qqfieldsct')='U' .AND. changing
  56.    @ qqrow,0 SAY 'Enter a QDM file name to change (without the QDM extension), OR,'
  57.    ?
  58.    ACCEPT 'to cancel this process, just strike the Enter key: ' TO qqdmfile
  59.    IF LEN(TRIM(qqdmfile))=0
  60.       changing=.f.
  61.    ELSE
  62.       qqdmfile=qqdmfile+'.qdm'
  63.       * just beep on any error (file does not exist, etc.)
  64.       ON ERROR ?? chr(7)
  65.       RESTORE FROM &qqdmfile ADDITIVE
  66.       ON ERROR
  67.       @ qqrow,0 CLEAR TO 21,79
  68.       @ 1,0 SAY ''
  69.    ENDIF
  70. ENDDO
  71. IF changing
  72.    @ 1,0 CLEAR TO 21,79
  73.    @ 2,0 SAY 'Preparing text file for editing . . . '
  74.    ?
  75.    children=qqfielchil
  76.    file=0
  77.    tempname=SYS(3)
  78.    temptxt=tempname+'.TXT'
  79.    tempbak=tempname+'.BAK'
  80.    * copy the existing QDM to an ASCII text file
  81.    SET PRINTER TO &temptxt
  82.    SET PRINT ON
  83.    SET CONSOLE OFF
  84.    qqstndtitl=" Type   Width Dec═╦══════ Sample ═════"
  85.    IF TYPE('qqfieltitl')='U'
  86.       qqfieltitl=qqstndtitl
  87.    ENDIF
  88.    ?? "<alias>   "+qqfieltitl
  89.    ?
  90.    DO WHILE file<=children
  91.       IF file=0
  92.          items=qqfieldsct
  93.          qqarray='qqfields'
  94.       ELSE
  95.          qqchildnum=right(str(file+100,3),2)
  96.          qqcount='qqfielct'+qqchildnum
  97.          qqarray='qqfielar'+qqchildnum
  98.          qqcname='qqfielnm'+qqchildnum
  99.          ?? '..'+&qqcname+REPL('.',39)
  100.          ?
  101.          items=&qqcount
  102.       ENDIF
  103.       element=1
  104.       DO WHILE element<=items
  105.          ?? &qqarray.(element)
  106.          ?
  107.          element=element+1
  108.       ENDDO
  109.       file=file+1
  110.    ENDDO
  111.    SET CONSOLE ON
  112.    SET PRINT OFF
  113.    SET PRINTER TO PRN
  114.    @ 1,0 CLEAR TO 21,79
  115.    @ 1,0 SAY ''
  116.    * Edit the ASCII text version of the QDM file
  117.    IF AT('FOXPRO',UPPER(VERSION())) <> 0
  118.       DEFINE WINDOW EDITR FROM 2,12 TO 20,64 DOUBLE SHADOW
  119.       MODI FILE &temptxt WINDOW EDITR
  120.    ELSE
  121.       MODI COMM &temptxt
  122.    ENDIF
  123.    @ 0,0 GET qqbanner
  124.    CLEAR GETS
  125.    * Saved changes indicated by creation of BAK file
  126.    changing=FILE ('&tempbak')
  127.    IF changing
  128.       DELETE FILE &tempbak
  129.       ACCEPT 'CONFIRM: Replace existing QDM file?  (Yes/No) ' TO choice
  130.       changing=UPPER(choice)='Y'
  131.    ENDIF
  132.    IF .NOT. changing
  133.       @ 1,0 CLEAR TO 21,79
  134.       @ 2,0 SAY 'QDM file not changed.'
  135.       DELETE FILE &temptxt
  136.    ENDIF
  137. ENDIF
  138. IF changing
  139.    * Create a temporary DBF
  140.    tempdbf=SYS(3)
  141.    CLEAR TYPEAHEAD
  142.    KEYBOARD 'qdmdata'+CHR(13)+'C49'+CHR(13)+CHR(13)+CHR(13)+'N'
  143.    CREATE &tempdbf
  144.    @ 0,0 GET qqbanner
  145.    CLEAR GETS
  146.    @ 1,0 CLEAR TO 21,79
  147.    @ 2,0 SAY 'Creating new arrays . . . '
  148.    ?
  149.    * Fill the DBF with the contents of the modified ASCII text file
  150.    APPEND FROM &temptxt SDF
  151.    * delete the ASCII text file
  152.    DELETE FILE &temptxt
  153.    * delete any blank lines in the DBF
  154.    DELETE FOR LEN(TRIM(qdmdata))=0
  155.    GO TOP
  156.    * release existing QDM variables
  157.    RELEASE ALL LIKE QQFIEL*
  158.    * create a custom pop up window title variable if the title was changed
  159.    IF SUBSTR(qdmdata,11)<>qqstndtitl
  160.       qqfieltitl=SUBSTR(qdmdata,11,38)
  161.    ENDIF
  162.    * point past the title, to the first field of the master file
  163.    SKIP
  164.    file=0
  165.    qqarray='qqfields'
  166.    current=recno()
  167.    COUNT WHILE qdmdata<>'..' .AND. .NOT. EOF() TO qqfieldsct
  168.    goto current
  169.    DIMENSION qqfields(qqfieldsct)
  170.    element=1
  171.    ? '<MAIN>'
  172.    DO WHILE .NOT. EOF()
  173.        DO CASE
  174.           CASE qdmdata='..'
  175.              file=file+1
  176.              qqchildnum=right(str(file+100,3),2)
  177.              qqcount='qqfielct'+qqchildnum
  178.              qqarray='qqfielar'+qqchildnum
  179.              qqcname='qqfielnm'+qqchildnum
  180.              ? LOWER(SUBSTR(qdmdata,3,8))
  181.              &qqcname.=SUBSTR(qdmdata,3,8)
  182.              current=recno()
  183.              SKIP
  184.              COUNT WHILE qdmdata<>'..' .AND. .NOT. EOF() TO &qqcount
  185.              goto current
  186.              DIMENSION &qqarray.(&qqcount)
  187.              element=0
  188.           OTHERWISE
  189.              &qqarray.(element)=TRIM(qdmdata)
  190.        ENDCASE
  191.        SKIP
  192.        element=element+1
  193.    ENDDO
  194.    USE
  195.    IF file>0
  196.       qqfielchil=file
  197.    ENDIF
  198.    * save the new QDM
  199.    SAVE TO &qqdmfile ALL LIKE qqfiel*
  200.    * delete the temporay DBF
  201.    tempdbf=tempdbf+'.dbf'
  202.    DELE FILE &tempdbf
  203.    ?
  204.    ? 'New QDM saved.'
  205. ENDIF
  206. SET TALK ON
  207. SET SAFE ON
  208. RETURN
  209.